import {
  getMyFollowFans,
  setFollow,
  getOtherFansFocus,
} from "@/static/js/my.js";
export default {
  data() {
    return {
      fansList: [],
      page: 1,
      is_focus: 0,
      id: "",
      type: "",
    };
  },
  onLoad(e) {
    if (e.id) {
      this.id = e.id;
      this.type = e.type;
      this.getFansFocus();
      uni.setNavigationBarTitle({
        title: this.type == 1 ? "ta的关注" : "ta的粉丝",
      });
    } else {
      this.getMyFollowFans();
    }
  },
  onShow() { },
  methods: {
    async getMyFollowFans() {
      var params = {
        type: 2,
      };
      let { code, data, msg } = await getMyFollowFans(params);
      if (code == 1) {
        this.fansList = data;
      }
    },

    async getFansFocus() {
      var params = {
        type: this.type,
        uid: this.id,
      };
      let { code, data, msg } = await getOtherFansFocus(params);
      if (code == 1) {
        this.fansList = data;
      }
    },
    async gzFun(item) {
      let params = {
        uid: item.id,
      };
      let res = await setFollow(params);
      if (res.code == 1) {
        this.$tools.msg(this.is_focus == 1 ? "取消成功" : "关注成功");
        this.is_focus = 1 - this.is_focus;
        if (this.id) {
          this.getFansFocus();
        } else {
          this.getMyFollowFans();
        }
      } else {
        this.$tools.msg(res.msg);
      }
    },
    toHome(item) {
      if (item.is_major == 1) {
        uni.navigateTo({
          url: "/pages/my/homeCenter/taTeacherHome?id=" + item.uid,
        });
      } else {
        uni.navigateTo({
          url: "/pages/my/homeCenter/taHome?id=" + item.uid,
        });
      }
    },
  },
};